import webapp2
from google.appengine.api import users
from util.webapp import ShopkeepApplication, ShopkeepHandler
from models.Log import Log

class LogPage(ShopkeepHandler):
	def get(self):
		user = users.get_current_user()

		logs = Log.all()
		if self.log_level in range(0, 6):
			logs.filter('level =', self.log_level)
		self.render_response("log_view.html", {'logs': logs.run()})
	
	@webapp2.cached_property
	def log_level(self):
		info = self.request.path.split('/')
		assert info[0] == ''

		if len(info) == 2:
			try:
				level = int(info[1])
				return level
			except ValueError:
				return -1
		else:
			return -1
		
app = ShopkeepApplication([('/log(?:/.*)?', LogPage)])
